"""
2017.06.02
"""


def sanitize(time_string):
    """
    过滤(净化)
    :param time_string:
    :return:
    """
    if '-' in time_string:
        splitter = '-'
    elif ':' in time_string:
        splitter = ':'
    else:
        return time_string
    (mins, secs) = time_string.split(splitter)
    return mins + '.' + secs


with open('james.txt') as jaf:
    data = jaf.readline().strip().split(',')
james = []  # 创建
for d in data:  # 迭代
    james.append(sanitize(d))  # 转换
print(sorted(james))  # 排序

'''使用列表推导'''
with open('julie.txt') as juf:  # 打开文件，读取一行
    data = juf.readline().strip().split(',')
# julie = []
# for d in data.strip().split(','):
#     julie.append(sanitize(d))

# 列表推导
julie = [sanitize(d) for d in data]

print(sorted(julie))

'''列表推导的列子'''
# 变成分钟
mins = [1, 2, 3]
secs = [m * 60 for m in mins]
print(secs)
# 转换成大写
lower = ['I', "don't", 'like', 'suger']
upper = [s.upper() for s in lower]
print(upper)


# 读取教练的数据
def get_coach_data(filename):
    try:
        with open(filename) as f:
            line = f.readline()
        return line.strip().split(',')
    except IOError as err:
        print('File error: ' + str(err))
        return None


# 获取前三次不重复的最快的数据
sara = get_coach_data('sarah.txt')
print(sorted(set(sanitize(d) for d in sara))[0:3])

